import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait


def search_homework():
    driver=webdriver.Chrome()
    driver.get("https://ceshiren.com/")
    time.sleep(1)
    driver.find_element(By.CSS_SELECTOR,"#ember6 > header > div > div > div.panel.clearfix > span > button.widget-button.btn.btn-primary.btn-small.login-button.btn-icon-text > span").click()
    time.sleep(1)
    driver.find_element(By.ID,"login-account-name").send_keys("3211473463@qq.com")
    time.sleep(1)
    driver.find_element(By.ID, "login-account-password").send_keys("hogwarts")
    time.sleep(1)
    driver.find_element(By.CSS_SELECTOR,"#login-button > span").click()
    time.sleep(4)

    driver.find_element(By.CSS_SELECTOR,"#search-button > svg").click()
    time.sleep(1)
    driver.find_element(By.ID,"search-term").send_keys("ChromeDriver")
    time.sleep(1)
    driver.find_element(By.XPATH,"//*[@id='ember6']/header/div/div/div[2]/div/div/div/div/div[1]/div/a[2]").click()
    time.sleep(1)

    el=driver.find_element(By.CSS_SELECTOR,"search-results .fps-result:nth-child(1) .topic-title>span")
    el.click()
    assert el.text =="selenium&chromedriver安装配置ok，在pycharm中执行代码失败，报错：’chromedriver’ executable needs to be in Path"

if __name__ == '__main__':
    search_homework()
